#ifndef POINTRENDERER_H
#define POINTRENDERER_H

#include <qopengl.h>

#include <QVector>
#include <QVector3D>
#include <QVector4D>

#include <qrender/renderer.h>

class QOpenGLShaderProgram;
class QOpenGLVertexArrayObject;
class QOpenGLBuffer;

class SphereRenderer : public Renderer
{
public:
    SphereRenderer();
    ~SphereRenderer();

    void setPosition(const QVector3D &pos);
    void setShape(float radius, int latitudes, int longitudes, QVector4D color);

protected:
    void create() override;
    void render(const CameraInfo &camera) override;
    void release() override;

private:
    /// 生成球体顶点坐标
    void generateSphereVertices(float radius, int latitudes, int longitudes);

private:
    QVector3D pos_{ 0, 0, 0 };
    float radius_{ 10.0 };
    int latitudes_{ 100 };
    int longitudes_{ 100 };
    QVector4D color_{ 0.0, 1.0, 1.0, 1.0 };
    bool data_changed_{ true };

    std::shared_ptr<QOpenGLShaderProgram> program_{ nullptr };
    std::shared_ptr<QOpenGLVertexArrayObject> vao_{ nullptr };
    std::shared_ptr<QOpenGLBuffer> vbo_{ nullptr };

    QVector<QVector3D> vertices_;
    QVector<GLuint> indices_;
};

#endif // POINTRENDERER_H
